package cn.tips.dmp.supports.i18n;

import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;

/**
 * 根据地域获取i18n中词条工具类
 *
 * @author pkb
 */
@Component
public class MessageUtils {

    private final MessageSource messageSource;

    public MessageUtils(MessageSource messageSource) {
        this.messageSource = messageSource;
    }

    /**
     * 获取词条
     *
     * @param key 对应message.properties中key
     * @return String类型message
     */
    public String getMessage(String key) {
        return messageSource.getMessage(key, new String[]{}, LocaleContextHolder.getLocale());
    }

}
